<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>安全管理员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote layui-quote-nm">
            提示：安全管理员不要随意删除哦！若删除将导致业务系统及渗透测试报告模块中的安全管理员数据为空
        </blockquote>

        <fieldset class="table-search-fieldset">
            <legend>安全管理员搜索</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">管理员</label>
                            <div class="layui-input-inline">
                                <input type="text" name="managerName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i>
                                搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarManager">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"><i class="layui-icon">&#xe624;</i>添加安全管理员</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTable_manager" lay-filter="ManagerTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete"><i class="layui-icon">&#xe640;</i>删除</a>
        </script>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTable_manager',
            url: "/api/assets/manager",
            toolbar: '#toolbarManager',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '刷新',
                layEvent: 'Refresh',
                icon: 'layui-icon-refresh-3'
            }],
            cols: [
                [{
                    field: 'id',
                    width: 80,
                    title: 'ID',
                    sort: true
                },
                    {
                        field: 'manager_name',
                        width: 200,
                        title: '安全管理员'
                    },
                    {
                        field: 'web_count',
                        width: 150,
                        title: 'web资产数'
                    },
                    {
                        field: 'level_no_count',
                        width: 150,
                        title: '未整改漏洞数'
                    },
                    {
                        field: 'level_yes_count',
                        width: 150,
                        title: '已整改漏洞数'
                    },
                    {
                        field: 'level_count',
                        width: 150,
                        title: '漏洞总数'
                    },
                    {
                        field: 'cus_time',
                        width: 300,
                        title: '添加时间'
                    },
                    {
                        title: '操作',
                        minWidth: 150,
                        toolbar: '#currentTableBar',
                        align: "center"
                    }
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 20,
            page: true,
            skin: 'line'
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTable_manager', {
                page: {
                    curr: 1
                },
                where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        table.on('tool(ManagerTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('慎重！确定删除该安全管理员吗？若删除将导致业务系统及渗透测试报告模块中的安全管理员数据为空', function (index) {
                    $.ajax({
                        url: "/api/assets/manager",
                        data: JSON.stringify(data),
                        contentType: 'application/json;charset=UTF-8',
                        dataType: 'json',
                        type: 'delete',
                        success: function (result) {
                            if (result.code == 200) {
                                layer.alert('删除管理员成功!', {
                                    title: '提示',
                                    icon: 1
                                })
                                obj.del();
                                layer.close(index);
                                table.reload('currentTable_manager', {
                                    page: {
                                        curr: 1
                                    }
                                    ,
                                }, 'data');
                            } else {
                                layer.alert(result.msg, {
                                    title: '提示',
                                    icon: 2
                                })
                                layer.close(index);
                            }
                        },
                        error: function (e) {
                            layer.alert(JSON.stringify(e), {
                                title: '提示',
                                icon: 2
                            })
                        }
                    })
                    layer.close(index);
                });
            }
        });

        table.on('toolbar(ManagerTableFilter)', function (obj) {
            if(obj.event === 'Refresh'){
                table.reload('currentTable_manager', {
                    page: {
                        curr: 1
                    }
                    ,
                }, 'data');
            }else if(obj.event === 'add'){
                var managerindex = layer.open({
                    title: '添加安全管理员',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "/assets/manager/add",
                });
                $(window).on("resize", function () {
                    layer.full(managerindex);
                });
            }
        });
    });
</script>

</body>
</html>
